const { defineConfig } = require('@vue/cli-service')
let {list}=require('./src/mock')
const bodyParser =require('body-parser')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer:{
    setupMiddlewares(middlewares,{app}){
      app.use(bodyParser.json())
      app.get('/api/list',(req,res)=>{
        const {page=1,pageSize=10,input=''}=req.query
        const data=list.filter(v=>{
          if(input==='')return true
          return v.name.includes(input)
        })
        
        res.send({
          list:data.slice((page-1)*pageSize,page*pageSize),
          listLength:data.length
        })
      })
      app.post('/api/dele',(req,res)=>{
        const {id}=req.body
        list.map(v=>{
          if(v.id===id){
            return Object.assign(v,req.body)
          }
          return v
        })
        res.send({
          code:200
        })
      })
      return middlewares
    }
  }
})
